package com.franklin.ideaplugin.easytesting.linemarker;

import com.franklin.ideaplugin.easytesting.action.MethodActionGroup;
import com.franklin.ideaplugin.easytesting.action.RunMethodAction;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.DocumentListener;
import com.intellij.openapi.editor.markup.GutterIconRenderer;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Collection;
import java.util.Optional;

/**
 * @author Franklin
 * @since 2021/9/6 19:58
 */
class SelectMethodLineMarkerInfo extends LineMarkerInfo<PsiMethod> {

    protected PsiMethod element;

    protected RunMethodAction runMethodAction;

    SelectMethodLineMarkerInfo(
        @NotNull PsiMethod element,
        @NotNull Icon icon,
        Navigatable navigatable,
        Collection<String> fixTargets
    ) {
        super(element, element.getTextRange(),
            icon, xmlTag -> "Fix map column names you had changed",
            (mouseEvent, xmlTag) -> {

            },
            GutterIconRenderer.Alignment.CENTER,
            () -> String.join(",", fixTargets)
        );
        this.element = element;
        this.runMethodAction = new RunMethodAction(element);
    }

    @Override
    public GutterIconRenderer createGutterRenderer() {
        return new LineMarkerGutterIconRenderer<>(this) {

            public AnAction getClickAction() {
                return runMethodAction;
            }

            public boolean isNavigateAction() {
                return true;
            }

            @Override
            public @Nullable
            ActionGroup getPopupMenuActions() {
                return null;
            }

        };
    }

}
